package com.joolun.web.controller.scrm;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.joolun.common.annotation.Log;
import com.joolun.common.core.controller.BaseController;
import com.joolun.common.core.domain.AjaxResult;
import com.joolun.common.enums.BusinessType;
import com.joolun.system.domain.ScrmChannel;
import com.joolun.system.service.IScrmChannelService;
import com.joolun.common.utils.poi.ExcelUtil;
import com.joolun.common.core.page.TableDataInfo;

/**
 * 投放渠道Controller
 * 
 * @author joolun
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/scrm/channel")
public class ScrmChannelController extends BaseController
{
    @Autowired
    private IScrmChannelService scrmChannelService;

    /**
     * 查询投放渠道列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ScrmChannel scrmChannel)
    {
        startPage();
        List<ScrmChannel> list = scrmChannelService.selectScrmChannelList(scrmChannel);
        return getDataTable(list);
    }

    /**
     * 导出投放渠道列表
     */
    @PreAuthorize("@ss.hasPermi('system:channel:export')")
    @Log(title = "投放渠道", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScrmChannel scrmChannel)
    {
        List<ScrmChannel> list = scrmChannelService.selectScrmChannelList(scrmChannel);
        ExcelUtil<ScrmChannel> util = new ExcelUtil<ScrmChannel>(ScrmChannel.class);
        util.exportExcel(response, list, "投放渠道数据");
    }

    /**
     * 获取投放渠道详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:channel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scrmChannelService.selectScrmChannelById(id));
    }

    /**
     * 新增投放渠道
     */
    @PreAuthorize("@ss.hasPermi('system:channel:add')")
    @Log(title = "投放渠道", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScrmChannel scrmChannel)
    {
        scrmChannel.setCreateBy(getUsername());
        return toAjax(scrmChannelService.insertScrmChannel(scrmChannel));
    }

    /**
     * 修改投放渠道
     */
    @PreAuthorize("@ss.hasPermi('system:channel:edit')")
    @Log(title = "投放渠道", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScrmChannel scrmChannel)
    {
        scrmChannel.setCreateBy(getUsername());
        return toAjax(scrmChannelService.updateScrmChannel(scrmChannel));
    }

    /**
     * 删除投放渠道
     */
    @PreAuthorize("@ss.hasPermi('system:channel:remove')")
    @Log(title = "投放渠道", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scrmChannelService.deleteScrmChannelByIds(ids));
    }
}
